package com.like.banzipao.server.model

import com.fasterxml.jackson.annotation.JsonIgnore
import com.like.banzipao.server.util.roomstate.RoomManager

data class Room(val id: Int) {
    // 这里不能用 private ，否则无法被jackson序列化
    // 这里使用 Array，而非 List，是为了座位固定，达到正确的体验。
    val players = arrayOfNulls<Player>(4)
    val pokers = mutableListOf<Poker>()

    // 换牌数量
    var drawNumber: Int = 0

    @get:JsonIgnore
    val manager: RoomManager by lazy {
        RoomManager(this)
    }

    fun reset(user: User) {
        pokers.removeIf { it.holderUserId == user.id }
        players.find { it?.user?.id == user.id }?.reset()
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is Room) return false

        if (id != other.id) return false

        return true
    }

    override fun hashCode(): Int {
        return id
    }

    override fun toString(): String {
        return "Room(id=$id)"
    }
}
